package com.russell.pms.dao.hibernate;

import java.util.List;

import com.russell.pms.dao.TenantDao;
import com.russell.pms.model.Tenant;

/**
 * 
 * @author <a href="mailto:fvinluan@gmail.com">Francis Vinluan</a>
 * 
 * @version $Revision: 1.0 $
 */
public class TenantDaoHibernate extends BaseDaoHibernate implements TenantDao {

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.princess.etrak.dao.TenantDao#getTenant(java.lang.Short)
	 */
	/**
	 * Method getTenant.
	 * 
	 * @param id
	 *            Long
	 * 
	 * @return Tenant * @see com.princess.etrak.dao.TenantDao#getTenant(Long) * @see
	 *         com.princess.etrak.dao.TenantDao#getTenant(String) * @see
	 *         com.princess.etrak.dao.TenantDao#getTenant(String)
	 */
	public Tenant getTenant(int id) {
		if (logger.isDebugEnabled()) {
			logger.debug("getting tenant begins" + id);
		}
		Tenant tenant = (Tenant) getCurrentSession().get(Tenant.class, id);
		if (logger.isDebugEnabled()) {
			logger.debug("getting tenant ends ");
		}
		return tenant;
	}

	/**
	 * Gets a list of all tenant.
	 * 
	 * 
	 * @return List populated list of tenant * @see
	 *         com.princess.etrak.dao.TenantDao#getTenantList() * @see
	 *         com.princess.etrak.dao.TenantDao#getTenantList() * @see
	 *         com.princess.etrak.dao.TenantDao#getTenantList() * @see
	 *         com.princess.etrak.dao.TenantDao#getTenantList()
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<Tenant> getTenants() {
		if (logger.isDebugEnabled()) {
			logger.debug("getting all tenant begins");
		}
		List<Tenant> cList = getCurrentSession().createQuery("FROM Tenant")
				.list();
		if (cList == null || cList.size() < 1)
			return null;
		if (logger.isDebugEnabled()) {
			logger.debug("getting all tenant ends: ");
		}
		return cList;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.princess.etrak.dao.TenantDao#removeTenant(com.princess.ilo
	 * .model.Tenant)
	 */
	/**
	 * Method removeTenant.
	 * 
	 * @param tenant
	 *            Tenant
	 * 
	 * @see com.princess.etrak.dao.TenantDao#removeTenant(Tenant)
	 */
	public void removeTenant(Tenant tenant) {
		if (logger.isDebugEnabled()) {
			logger.debug("removeTenant begins");
		}
		getCurrentSession().delete(tenant);
		if (logger.isDebugEnabled()) {
			logger.debug("removeTenant ends");
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.princess.etrak.dao.TenantDao#saveTenant(com.princess.etrak.
	 * model.Tenant)
	 */
	/**
	 * Method saveTenant.
	 * 
	 * @param tenant
	 *            Tenant
	 * 
	 * @see com.princess.etrak.dao.TenantDao#saveTenant(Tenant)
	 */
	public void saveTenant(Tenant tenant) {
		if (logger.isDebugEnabled()) {
			logger.debug("saveTenant begins: " + tenant);
		}
		getCurrentSession().save(tenant);
		if (logger.isDebugEnabled()) {
			logger.debug("saveTenant ends");
		}
	}

	/**
	 * Method updateTenant.
	 * 
	 * @param tenant
	 *            Tenant
	 * 
	 * @see com.princess.etrak.dao.TenantDao#updateTenant(Tenant)
	 */
	@Override
	public void updateTenant(Tenant tenant) {
		if (logger.isDebugEnabled()) {
			logger.debug("updateTenant begins: " + tenant);
		}
		getCurrentSession().update(tenant);
		if (logger.isDebugEnabled()) {
			logger.debug("updateTenant ends");
		}
	}

}
